package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.businessproduct.pojo.vo.BusinessProductListVO;
import com.xbongbong.pro.detailtab.vo.DetailTabGetVO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.ProductSavePojo;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.pro.workorder.pojo.dto.ChangeWorkflowItemDTO;
import com.xbongbong.pro.workorder.pojo.dto.WorkOrderDeleteBatchDTO;
import com.xbongbong.pro.workorder.pojo.dto.WorkOrderEditAttrUpdateDTO;
import com.xbongbong.pro.workorder.pojo.dto.WorkOrderRestoreOutboundDTO;
import com.xbongbong.pro.workorder.pojo.dto.WorkOrderUpdateBatchDTO;
import com.xbongbong.pro.workorder.pojo.dto.WorkOrderUpdateByBusinessRuleDTO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderChangeFlowItemVO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderDeleteBatchVO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderEditAttrUpdateVO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderUpdateBatchVO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderUpdateByBusinessRuleVO;
import com.xbongbong.saas.domain.entity.WorkOrderEntity;
import com.xbongbong.saas.domain.entity.WorkOrderFlowNodeEntity;
import com.xbongbong.saas.domain.entity.WorkOrderProductEntity;
import com.xbongbong.saas.domain.entity.ext.WorkOrderEntityExt;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;


/**
 * 工单业务流转逻辑 service
 * @author 魏荣杰
 * @date 2019/3/21 14:19
 * @since v1.0
 * @version v1.0
 */
public interface WorkOrderService {

    /**
     * 工单 保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author 魏荣杰
     * @date 2019/3/21 14:24
     * @since v1.0
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 工单 保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author 魏荣杰
     * @date 2019/3/21 14:24
     * @since v1.0
     */
    void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * Description: 新建时格式化解释
     * @param formatExplainDTO 入参
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/3/28 15:32
     * @since v1.0
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;



    /**
     * 流转操作页
     * @return
     * @throws XbbException
     */
    WorkOrderChangeFlowItemVO getChangeFlowItem(ChangeWorkflowItemDTO changeWorkflowItemDTO) throws XbbException;

    /**
     * Description: 获取工单关联产品
     * @param businessProductListDTO
     * @return BusinessProductListVO
     * @throws XbbException
     * @author 刘阳
     * @date 2019/4/23 3:16 PM
     * @since v1.0
     */
    BusinessProductListVO getWorkOrderProductList(BusinessProductListDTO businessProductListDTO, Object object) throws XbbException;

    /**
     * Description: 保存工单产品备件
     * @param productArray  产品数据
     * @param corpid 公司id
     * @param workOrderId 工单id
     * @param formId
     * @return java.util.List<com.xbongbong.saas.domain.entity.WorkOrderProductEntity>
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/4/23 17:24
     * @since v1.0
     */
    List<WorkOrderProductEntity> saveProduct(JSONArray productArray, String corpid, Long workOrderId, Long formId) throws XbbException;

    /**
     * Description: 格式化产品，显示给前端
     * @param dataList
     * @param saasAnalysisDataDTO
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/4/23 21:19
     * @since v1.0
     */
    void formatProduct4Show(JSONObject dataList, SaasAnalysisDataDTO saasAnalysisDataDTO) throws XbbException;


    /**
     * Description: 格式化工单移动端列表
     * @param formDataListDTO
     * @param workOrderEntityExts
     * @param totalCount
     * @return com.xbongbong.pro.applist.pojo.vo.ListAppVO
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/5/6 19:59
     * @since v1.0
     */
    ListAppVO formatWorkOrderAppList(FormDataListDTO formDataListDTO, List<WorkOrderEntityExt> workOrderEntityExts, Integer totalCount) throws XbbException;

    /**
     * Description: 获取可接收工单人员
     * @param corpid
     * @param isFree
     * @param entity
     * @param workOrderFlowNodeEntity
     * @author 刘阳
     * @date 2019/8/12 9:48 AM
     * @since v1.0
     */
    List<String> getAcceptUserIds(String corpid, boolean isFree, WorkOrderEntity entity, WorkOrderFlowNodeEntity workOrderFlowNodeEntity);

    /**
     * Description: 格式化工单记录
     * @param formDataListDTO
     * @param workOrderEntityExts
     * @param totalCount
     * @return com.xbongbong.pro.applist.pojo.vo.ListAppVO
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/5/6 19:59
     * @since v1.0
     */
    ListAppVO formatWorkOrderRecord(FormDataListDTO formDataListDTO, List<WorkOrderEntityExt> workOrderEntityExts, Integer totalCount) throws XbbException;

    /**
     * Description: 格式化工单移动端列表(web)
     * @param formDataListDTO
     * @param workOrderEntityExts
     * @param totalCount
     * @return com.xbongbong.pro.detailtab.vo.DetailTabGetVO
     * @throws XbbException XbbException
     * @author 刘阳
     * @date 2019/5/17 2:50 PM
     * @since v1.0
     */
    DetailTabGetVO formatWorkOrderWebList(FormDataListDTO formDataListDTO, List<WorkOrderEntityExt> workOrderEntityExts, Integer totalCount) throws XbbException;


    /**
     * Description: 批量删除工单
     * @param workOrderDeleteBatchDTO
     * @return com.xbongbong.pro.workorder.pojo.vo.WorkOrderDeleteBatchVO
     * @throws XbbException
     * @author 魏荣杰
     * @date 2019/5/9 10:34
     * @since v1.0
     */
    WorkOrderDeleteBatchVO deleteBatch(WorkOrderDeleteBatchDTO workOrderDeleteBatchDTO) throws XbbException;

    /**
     * Description: 批量编辑单个字段
     * @param workOrderEditAttrUpdateDTO
     * @return WorkOrderEditAttrUpdateVO
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/5/9 17:07
     * @since v1.0
     */
    WorkOrderEditAttrUpdateVO batchEditAttr(WorkOrderEditAttrUpdateDTO workOrderEditAttrUpdateDTO) throws XbbException;
    /**
     * Description: 批量更新
     * @param workOrderUpdateBatchDTO
     * @return WorkOrderUpdateBatchVO
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/5/9 17:24
     * @since v1.0
     */
    WorkOrderUpdateBatchVO updateBatch(WorkOrderUpdateBatchDTO workOrderUpdateBatchDTO) throws XbbException;

    /**
     * Description: 关联新建时格式化解释
     * @param handlerExplainInLinkItemDTO
     * @return void
     * @throws XbbException XbbException
     * @author 魏荣杰
     * @date 2019/5/23 17:22
     * @since v1.0
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * Description:格式化导出值
     * @param importFormDataDTO 入参
     * @param titlePojoList 标题
     * @param rowGroupPojo 组
     * @param fieldAttrList 解释
     * @throws XbbException 异常
     * @author 刘阳
     * @date 2019/6/9 10:56 AM
     * @since v1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出数据
     *
     * @param paasFormDataESList 数据
     * @param formDataListDTO 入参
     * @param fieldAttrList 解释
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;
    /**
     * Description: 一致性同步客户
     * @param corpid
     * @param customerId
     * @param customerName
     * @author 魏荣杰
     * @date 2019/6/12 9:48
     * @since v1.0
     */
    void dataConsistencyUpdateCustomer(String corpid, Long customerId, String customerName) throws XbbException;
    /**
     * Description: 删除出库单后更改出库状态和合同状态
     * @param workOrderRestoreOutboundDTO
     * @author 魏荣杰
     * @date 2019/6/18 15:30
     * @since v1.0
     */
    void restoreOutboundAndStatus(WorkOrderRestoreOutboundDTO workOrderRestoreOutboundDTO) throws XbbException;

    /**
     * 出库单保存后判断是否出库完毕
     * @param outstockId
     * @param refId
     * @param corpid
     * @param productSavePojoList
     * @return
     */
    Integer judgeWorkOrderAllOutBound(Long outstockId, Long refId, String corpid, List<ProductSavePojo> productSavePojoList) throws XbbException;

    /**
     * 汇总工单产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     * 根据业务规则更新工单
     * @param workOrderUpdateByBusinessRuleDTO
     * @return
     * @throws XbbException
     */
    WorkOrderUpdateByBusinessRuleVO updateBatchByBusinessRule(WorkOrderUpdateByBusinessRuleDTO workOrderUpdateByBusinessRuleDTO) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    /**
     * 解析单个产品
     * @param entity
     * @return
     */
    JSONObject formatSingleProduct(WorkOrderProductEntity entity);

    /**
     * Description: 同步工单关联的合同编号
     * @param corpid
     * @param contractId
     * @param serialNo
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/8/4 10:02
     * @since
     */
    void dataConsistencyUpdateContract(String corpid, Long contractId, String serialNo);

    /**
     * 批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkFlow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
